package com.ynding.cloud.auth.api.authentication.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ynding.cloud.auth.api.authentication.service.IAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.stream.Stream;

/**
 * <p> </p>
 *
 * @author ynding
 * @version 2021/6/22
 **/
@Service
@Slf4j
public class AuthServiceImpl implements IAuthService {

//    @Autowired
//    private OauthClient oauthClient;

    /**
     * 不需要网关签权的url配置(/oauth,/open)
     * 默认/oauth开头是不需要的
     */
    @Value("${gate.ignore.urls}")
    private String ignoreUrls = "/oauth";

    @Override
    public boolean ignoreAuthentication(String url) {
        return Stream.of(this.ignoreUrls.split(",")).anyMatch(ignoreUrl -> url.startsWith(StrUtil.trim(ignoreUrl)));
    }

    @Override
    public String[] ignoreUrls() {
        return this.ignoreUrls.split(",");
    }

   /* @Override
    public boolean hasPermission(String authentication, String url, String method) {
        //token是否有效
        if (oauthClient.invalidJwtAccessToken(authentication).getCode() == 200) {
            return Boolean.FALSE;
        }
        //从认证服务获取是否有权限
        ResponseBean responseBean = oauthClient.auth(authentication,url,method);
        return responseBean.getCode() == 200;
    }*/
}
